<!-- 合同详情头部组件-->
<template>
  <div>
    <div class="flex items-start justify-between">
      <div>
        <el-col>
          <el-row>
            <span class="text-xl font-bold">{{ contract.name }}</span>
          </el-row>
        </el-col>
      </div>
      <div>
        <!-- 右上：按钮 -->
        <slot></slot>
      </div>
    </div>
  </div>
  <ContentWrap class="mt-10px">
    <el-descriptions :column="6" direction="vertical">
      <el-descriptions-item label="客户名称">
        {{ contract.customerName }}
      </el-descriptions-item>
      <el-descriptions-item label="合同金额（元）">
        {{ erpPriceInputFormatter(contract.totalPrice) }}
      </el-descriptions-item>
      <el-descriptions-item label="下单时间">
        {{ formatDate(contract.orderDate) }}
      </el-descriptions-item>
      <el-descriptions-item label="回款金额（元）">
        {{ erpPriceInputFormatter(contract.totalReceivablePrice) }}
      </el-descriptions-item>
      <el-descriptions-item label="回款状态">
        <el-tag type="danger" v-if="redemptionStatusIsNot(contract.totalReceivablePrice, contract.totalPrice)">
          未回款
        </el-tag>
        <el-tag  type="warning" v-if="redemptionStatusIsNotAll(contract.totalReceivablePrice, contract.totalPrice)">
          部分回款
        </el-tag>
        <el-tag type="success" v-if="redemptionStatusIsAll(contract.totalReceivablePrice, contract.totalPrice)">
          全部回款
        </el-tag>
      </el-descriptions-item>
      <el-descriptions-item label="负责人">
        {{ contract.ownerUserName }}
      </el-descriptions-item>
    </el-descriptions>
  </ContentWrap>
</template>
<script lang="ts" setup>
import * as ContractApi from '@/api/crm/contract'
import { formatDate } from '@/utils/formatTime'
import { erpPriceInputFormatter } from '@/utils'

defineOptions({ name: 'ContractDetailsHeader' })
defineProps<{ contract: ContractApi.ContractVO }>()
const redemptionStatusIsNot = (totalReceivablePrice,totalPrice) => {
  if (erpPriceInputFormatter(totalPrice) === '0.00' || erpPriceInputFormatter(totalPrice) === '') return false;
  return erpPriceInputFormatter(totalReceivablePrice) === '' || erpPriceInputFormatter(totalReceivablePrice) === '0.00';
}
const redemptionStatusIsNotAll = (totalReceivablePrice,totalPrice) => {
  if (erpPriceInputFormatter(totalPrice) === '0.00' || erpPriceInputFormatter(totalPrice) === ''||erpPriceInputFormatter(totalReceivablePrice) === '' || erpPriceInputFormatter(totalReceivablePrice) === '0.00') return false;
  // console.debug('redemptionStatusIsNotAll',totalReceivablePrice > 0 && totalPrice>totalReceivablePrice)
  return parseFloat(totalReceivablePrice) > 0 && parseFloat(totalPrice)>parseFloat(totalReceivablePrice);
}
const redemptionStatusIsAll = (totalReceivablePrice,totalPrice) => {
  if (erpPriceInputFormatter(totalPrice) === '0.00' || erpPriceInputFormatter(totalPrice) === ''||erpPriceInputFormatter(totalReceivablePrice) === '' || erpPriceInputFormatter(totalReceivablePrice) === '0.00') return false;
  // console.debug('redemptionStatusIsAll',totalPrice<=totalReceivablePrice)
  return parseFloat(totalPrice)<=parseFloat(totalReceivablePrice);
}
</script>
